<?php
class View {
	
	private static $isGenerated = false;
	private $_params= array();
	private $_default = array('title'=>'Forum des Mines', 'top'=>'topUserNotLogged','left'=>'leftColumn','center'=>'accueil');
	
	public function __construct($params=array('title'=>'Mon titre')) {
		$this->_params = array_merge($this->_default, $params);
	}
	
	public function render($params=array()) {
		if(!self::$isGenerated) {
			$this->renderInTop($this->_params['top']);
			$this->renderInLeft($this->_params['left']);
			$this->renderInCenter($this->_params['center']);
		}
		$this->setViewGenerated();
	}
	
	public function renderInTop($templateName='topUserNotLogged') {
		$this->setHeader();
		Loader::loadTemplate($templateName, $this->_params);
	}
	
	public function renderInLeft($templateName='leftColumnNotLogged') {
		Loader::loadTemplate($templateName, $this->_params);
	}
	
	public function renderInCenter($templateName='404') {
		Loader::loadTemplate($templateName, $this->_params);
	}
	
	public function getParams() {
		return $this->_params;
	}
	
	public function setParam($key, $value) {
		$this->setParams(array($key=>$value));
	}
	
	public function setParams($params=array()) {
		$this->_params = array_merge($this->_params,$params);
	}
	
	public function setObject($objectName, $object=null) {
		$this->setParam($objectName, $object);
	}
	
	public function setHeader() {
		Loader::loadTemplate('headers', $this->_params);
	}
	
	public function setViewGenerated($boolean=true) {
		self::$isGenerated=$boolean;
	}

}